The present invention relates to a method for converting a program written in an object-oriented language into an object program, a program for making a computer execute the method and a storage medium for recording the program thereon.
With recent increase in the size of programs, attention has been given to developments of programs using object-oriented languages such as C++ and Java (R), in order to increase the efficiency in developing programs, to reuse programs or to enhance the maintainability of programs.
In a conventional procedural language, emphasis is placed on procedures and a desired process is executed by a combination of procedural calls. On the other hand, in an object-oriented language, stress is laid on classes, which include data and operations of the data, and a desired process is executed by a combination of class objects and operations on them. These operations are called “member functions” in C++ or “methods” in Java (R).
In general, a large number of classes are used in one program, and thus an enormous number of member functions (methods) are used. Accordingly, if the size of a program is large, it is difficult for a programmer to know which member function (method) is actually used, and consequently an object program tends to include code of member functions (methods) which are not actually called. In view of this, a technique for reducing the number of member functions (methods) is significant for a compiler that converts a program written in an object-oriented language into an object program.
Examples of known technique for deleting member functions (methods) include a technique of examining all the programs to know whether member functions (methods) are actually used and of deleting some of the member functions (methods) which are not actually used (see, for example, Japanese Unexamined Patent Publication No. 2001-14171).
Object-oriented languages have the concept of polymorphism in which the behavior of an object changes depending on the entity of the object during execution of a program. In C++, a member function having polymorphism is called a virtual function. In Java (R), every method has polymorphism.
Use of a virtual function changes a member function called depending on an actual type of an object during execution of a program, and thus a static analysis of which member function is called at compile time is difficult. However, even if a virtual function is used, it is still possible to analyze member functions which are never called under some circumstances.
Examples of techniques for deleting uncallale virtual functions include a technique in which attention is directed to calls of virtual functions and member functions which can be called by the calls are tagged (see, for example, Japanese Unexamined Patent Publication No. 9-269898). With this technique, potentially-callable functions out of all the virtual functions are tagged and thereby it is determined that non-tagged functions are not callable.
However, in this known technique, virtual functions which are not actually called are not deleted in some cases because of an insufficient analysis.
In the technique disclosed in Japanese Unexamined Patent Publication No. 2001-14171, addresses of member functions are referred to but uncallable member functions may be determined to be necessary, so that redundant code is generated in some cases. To know whether a member function is actually called or not, it is necessary to analyze the entire program to ascertain how the address of the member function is used. However, this requires considerable time.
In the technique disclosed in Japanese Unexamined Patent Publication No. 9-269898, uncallable virtual functions are erroneously identified as callable functions, resulting in the possibility of unsuccessful deletion of redundant code.